﻿namespace DynamicChart.Service.FunctionConversion;

public class OracleSqlAdapter : ISqlFunctionAdapter
{
    public string DateConvert(string fieldName, string format = null)
    {
        string dateFormat = string.IsNullOrEmpty(format) ? "'YYYY-MM-DD'" : $"'{format}'";
        return $"TO_CHAR({fieldName}, {dateFormat})";
    }

    public string DefaultConvert(string functionName, string fieldName)
    {
        return $"{functionName}({fieldName})";
    }

    public string FormatValue(string value)
    {
        return value;
    }
    
    public string GetDateFormat(string format)
    {
        switch (format)
        {
            case "day":
                return "YYYY-MM-DD";
            case "month":
                return "YYYY-MM";
            default:
                return "YYYY";
        }
    }
    
    public string LikeConvert(string fieldName, string parameterName)
    {
        return $"{fieldName} like '%:{parameterName}%'";;
    }
    
    public string EmptyConvert(string fieldName)
    {
        return fieldName;
    }
}